﻿using BestPracticesMVC.Data.DataModels;
using BestPracticesMvc.Data.DataModels;
using System;
using System.Data.Entity;
using System.Linq;
using System.Data.Entity.Infrastructure.Annotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace BestPracticesMvc.Data.Orm
{
    public class ProjectContext : DbContext
    {
        public ProjectContext() : base("Default")
        {
        }

        public DbSet<Book> Students { get; set; }

        public DbSet<Author> Authors { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder) 
        { 
            modelBuilder.Entity<Author>()
                        .Property(e => e.Name)
                        .HasColumnAnnotation(
                             "Index",
                             new IndexAnnotation(new[]
                             {
                                 new IndexAttribute("Index1")
                                // new IndexAttribute("Index2") { IsUnique = true }
                             }));
             //modelBuilder.Entity<Author>()
             //           .Property(e => e.Id)
             //           .HasColumnAnnotation(
             //                "Index",
             //                new IndexAnnotation(new[]
             //                {
             //                    new IndexAttribute("Index1",2),
             //                   // new IndexAttribute("Index2") { IsUnique = true }
             //                }));
        }
    }
}